import 'world.dart';
import 'command_handler.dart';
import 'focus.dart';
import 'sightable.dart';
import 'eventable.dart';
import 'displayer.dart';

class Engine {
  static Engine instance = Engine();
  Displayer displayer;
  Function initData;
  void init(){
    initData();

    Focus.instance.moveTo(World.instance.root);
  }

  void waitForInput(){
    displayer.displayString('输入想要做的事情：');
    displayer.displayString(Focus.current.sight());
  }

  void handleInput(String input) async{
    var command = Focus.current.point.commandForIndexOrName(input.toString());
    if (command == null) {
      displayer.displayString('错误命令');
    } else {
      if (command is Sightable) {
        CommandHandler.instance.handle(command);
        Focus.current.moveTo(command);
      } else if (command is Eventable) {
        displayer.displayString('开始 '+command.name);
        await command.doEvent(Focus.current.point);
      }
    }
    await Future.delayed(Duration(seconds:1));
  }
}